package com.ruoyi.web.controller.production.pesticide;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.production.domain.pesticide.PesticideApplyTemporary;
import com.ruoyi.production.service.pesticide.IPesticideApplyTemporaryService;
import io.netty.util.internal.UnstableApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 农药临时申请Controller
 *
 * @author ruoyi
 * @date 2021-07-11
 */
@RestController
@RequestMapping("/pesticide/applyTemporary")
@Api(value = "农药临时申请",tags = "农药临时申请相关API")
public class PesticideApplyTemporaryController extends BaseController
{
    @Autowired
    private IPesticideApplyTemporaryService pesticideApplyTemporaryService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询农药临时申请列表
     */
    @PreAuthorize("@ss.hasPermi('pesticide:applyTemporary:list')")
    @GetMapping("/list")
    @ApiOperation("获取农药临时申请列表")
    @ApiImplicitParam(name = "pesticideApplyTemporary", value = "农药临时申请实体", paramType = "body", dataType = "PesticideApplyTemporary")
    public TableDataInfo list(PesticideApplyTemporary pesticideApplyTemporary)
    {
        startPage();
        List<PesticideApplyTemporary> list = pesticideApplyTemporaryService.selectPesticideApplyTemporaryList(pesticideApplyTemporary);
        return getDataTable(list);
    }

    /**
     * 导出农药临时申请列表
     */
    @PreAuthorize("@ss.hasPermi('pesticide:applyTemporary:export')")
    @Log(title = "农药临时申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出农药临时申请数据")
    @ApiImplicitParam(name = "pesticideApplyTemporary", value = "农药临时申请实体", paramType = "body", dataType = "PesticideApplyTemporary")
    public AjaxResult export(PesticideApplyTemporary pesticideApplyTemporary)
    {
        List<PesticideApplyTemporary> list = pesticideApplyTemporaryService.selectPesticideApplyTemporaryList(pesticideApplyTemporary);
        ExcelUtil<PesticideApplyTemporary> util = new ExcelUtil<PesticideApplyTemporary>(PesticideApplyTemporary.class);
        return util.exportExcel(list, "农药临时申请数据");
    }

    /**
     * 获取农药临时申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('pesticide:applyTemporary:query')")
    @GetMapping(value = "/{pesticideApplyTemporaryId}")
    @ApiOperation("获取农药临时申请详细信息")
    @ApiImplicitParam(name = "pesticideApplyTemporaryId", value = "农药临时申请主键", paramType = "path", dataType = "Long")
    public AjaxResult getInfo(@PathVariable("pesticideApplyTemporaryId") Long pesticideApplyTemporaryId)
    {
        return AjaxResult.success(pesticideApplyTemporaryService.selectPesticideApplyTemporaryById(pesticideApplyTemporaryId));
    }

    /**
     * 新增农药临时申请
     */
    @PreAuthorize("@ss.hasPermi('pesticide:applyTemporary:add')")
    @Log(title = "农药临时申请", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增农药临时申请信息")
    @ApiImplicitParam(name = "pesticideApplyTemporary", value = "农药临时申请实体类", paramType = "body", dataType = "PesticideApplyTemporary")
    public AjaxResult add(@RequestBody PesticideApplyTemporary pesticideApplyTemporary)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        pesticideApplyTemporary.setUserId(loginUser.getUser().getUserId());
        return toAjax(pesticideApplyTemporaryService.insertPesticideApplyTemporary(pesticideApplyTemporary));
    }

    /**
     * 修改农药临时申请
     */
    @PreAuthorize("@ss.hasPermi('pesticide:applyTemporary:edit')")
    @Log(title = "农药临时申请", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改农药临时申请信息")
    @ApiImplicitParam(name = "pesticideApplyTemporary", value = "农药临时申请实体类", paramType = "body", dataType = "PesticideApplyTemporary")
    public AjaxResult edit(@RequestBody PesticideApplyTemporary pesticideApplyTemporary)
    {
        return toAjax(pesticideApplyTemporaryService.updatePesticideApplyTemporary(pesticideApplyTemporary));
    }

    /**
     * 删除农药临时申请
     */
    @PreAuthorize("@ss.hasPermi('pesticide:applyTemporary:remove')")
    @Log(title = "农药临时申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pesticideApplyTemporaryIds}")
    @ApiOperation("删除农药临时申请信息")
    @ApiImplicitParam(name = "pesticideApplyTemporaryIds", value = "农药临时申请主键数组", paramType = "path", dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] pesticideApplyTemporaryIds)
    {
        return toAjax(pesticideApplyTemporaryService.deletePesticideApplyTemporaryByIds(pesticideApplyTemporaryIds));
    }
}
